package avicit.cbb.techclass.billdefine.action.rest;


import avicit.cbb.techclass.billdefine.action.service.BillDefineDynamicService;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.CbbTabColumns;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：jiam
 * @邮箱：jiam@avic-digital.com
 * @创建时间： 2020-12-31 14:52
 * @类说明：oa_travel_rbRest
 * @修改记录：
 */

@RestController
@Api(tags = "BillDefineDynamicService", description = "BillDefine_Dynamic_Service")
@RequestMapping("/api/BillDefineDynamicService/BillDefineDynamicServiceRest")
public class BillDefineDynamicServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(BillDefineManagerRest.class);


    @Autowired(required = true)
    private BillDefineDynamicService billDefineDynamicService;


    /**
     * 获取动态DETAIL页面HTML
     * @param map
     * @return
     */
    @PostMapping("/getDynamicDetailHtml")
    @ApiOperation(value = "获取动态DETAIL页面HTML")
    public ResponseMsg<String> getDynamicDetailHtml(@ApiParam(value = "获取动态DETAIL页面HTML", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        String dynamicDetailHtml = null;
        try {
            List<Map<String, Object>> editList = (List<Map<String, Object>>) map.get("editList");
            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) map.get("mapCode");
            Map<String, Object> dynamicMap = (Map<String, Object>) map.get("dynamicMap");
            dynamicDetailHtml = billDefineDynamicService.getDynamicDetailHtml(editList, mapCode, dynamicMap);
            responseMsg.setResponseBody(dynamicDetailHtml);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }



    /**
     *获取datagrid的html
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getDatagridHtml/v1")
    @ApiOperation(value = "获取datagrid的html")
    public ResponseMsg<String> getDatagridHtml(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
            String getDatagridHtml = billDefineDynamicService.getDatagridHtml(param);
            responseMsg.setResponseBody(getDatagridHtml);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }




//    /**
//     *
//     * @param resMapsRb
//     * @return
//     */
//    @PostMapping("/getDynamicDetailHtml/v1")
//    @ApiOperation(value = "")
//    public ResponseMsg<String> getDynamicDetailHtml(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
//        ResponseMsg<String> responseMsg = new ResponseMsg<>();
//        try {
//            List<Map<String, Object>> formShowList = (List<Map<String, Object>>) resMapsRb.get("formShowList");
//            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) resMapsRb.get("mapCode");
//            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
//            String getDynamicDetailHtml = billDefineDynamicService.getDynamicDetailHtml(formShowList,mapCode,param);
//            responseMsg.setResponseBody(getDynamicDetailHtml);
//            responseMsg.setRetCode("200");
//        } catch (Exception e) {
//            responseMsg.setErrorDesc(e.getMessage());
//            responseMsg.setRetCode("201");
//            e.printStackTrace();
//        }
//        return responseMsg;
//    }




    /**
     *获取动态SEARCH页面HTML
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getDynamicSearchHtml/v1")
    @ApiOperation(value = "")
    public ResponseMsg<String> getDynamicSearchHtml(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> formShowList = (List<Map<String, Object>>) resMapsRb.get("formShowList");
            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) resMapsRb.get("mapCode");
            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
            String getDynamicSearchHtml = billDefineDynamicService.getDynamicSearchHtml(formShowList,mapCode,param);
            responseMsg.setResponseBody(getDynamicSearchHtml);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }




    /**
     *获取动态EDIT页面HTML
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getDynamicEditHtml/v1")
    @ApiOperation(value = "")
    public ResponseMsg<String> getDynamicEditHtml(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> formShowList = (List<Map<String, Object>>) resMapsRb.get("formShowList");
            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) resMapsRb.get("mapCode");
            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
            String getDynamicEditHtml = billDefineDynamicService.getDynamicEditHtml(formShowList,mapCode,param);
            responseMsg.setResponseBody(getDynamicEditHtml);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }




    /**
     *获取动态ADD页面HTML
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getDynamicAddHtml/v1")
    @ApiOperation(value = "")
    public ResponseMsg<String> getDynamicAddHtml(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> formShowList = (List<Map<String, Object>>) resMapsRb.get("formShowList");
            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) resMapsRb.get("mapCode");
            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
            String getDynamicAddHtml = billDefineDynamicService.getDynamicAddHtml(formShowList,mapCode,param);
            responseMsg.setResponseBody(getDynamicAddHtml);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }




    /**
     *获取动态DETAIL页面HTML
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getDynamicDetailHtmlByInput/v1")
    @ApiOperation(value = "")
    public ResponseMsg<String> getDynamicDetailHtmlByInput(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> formShowList = (List<Map<String, Object>>) resMapsRb.get("formShowList");
            Map<String, Map<String, String>> mapCode = (Map<String, Map<String, String>>) resMapsRb.get("mapCode");
            Map<String, Object> param = (Map<String, Object>) resMapsRb.get("param");
            String getDynamicDetailHtmlByInput = billDefineDynamicService.getDynamicDetailHtmlByInput(formShowList,mapCode,param);
            responseMsg.setResponseBody(getDynamicDetailHtmlByInput);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }




    /**
     *通过配置文件获取附件相应字段
     * @param resMapsRb
     * @return
     */
    @PostMapping("/getAttachmentClassMapByProperties/v1")
    @ApiOperation(value = "")
    public ResponseMsg<List<Map<String, Object>>> getAttachmentClassMapByProperties(@ApiParam(value = "", name = "filebasicmanagerservice")@RequestBody Map<String,Object> resMapsRb) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> getAttachmentClassMapByProperties = billDefineDynamicService.getAttachmentClassMapByProperties();
            responseMsg.setResponseBody(getAttachmentClassMapByProperties);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setErrorDesc(e.getMessage());
            responseMsg.setRetCode("201");
            e.printStackTrace();
        }
        return responseMsg;
    }





}
